package com.dandev.cmdemo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dandev.cmdemo.form.Communique;
import com.dandev.cmdemo.form.Contact;
import com.dandev.cmdemo.dao.ContactDAO;

@Service
public class ContactServiceImpl implements ContactService {
	
	@Autowired
    private ContactDAO contactDAO;
	
	@Transactional
	public void addContact(Contact contact) {
		String firstName = contact.getFirstName();
		if(firstName != null) {
			if(firstName.trim().length() == 0) {
				contact.setFirstName(null);
			}
		}
		contactDAO.addContact(contact);
	}

	@Transactional
	public List<Contact> listContact() {
		return contactDAO.listContact();
	}

	@Transactional
	public Contact getContact(Long id) {
		return contactDAO.getContact(id, false);
	}
	
	@Transactional
	public Contact getContact(Long id, boolean loadConn) {
		return contactDAO.getContact(id, loadConn);
	}

	@Transactional
	public void removeContact(Long id) {
		contactDAO.removeContact(id);

	}
	
	@Transactional
	public void addCommunique(Communique comm) {
		contactDAO.addCommunique(comm);
	}
	
	@Transactional
	public Communique getCommunique(Long id) {
		return contactDAO.getCommunique(id);
	}
	
	@Transactional
	public void removeCommunique(Long id) {
		contactDAO.removeCommunique(id);
	}

}
